package pe.gob.mpfn.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.validator.LengthValidator;
import org.primefaces.component.autocomplete.AutoComplete;
import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.inputtextarea.InputTextarea;
import org.primefaces.component.message.Message;
import org.primefaces.context.RequestContext;
import org.primefaces.event.CloseEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.jsf.managedbean.RooJsfManagedBean;
import org.springframework.roo.addon.serializable.RooSerializable;
import pe.gob.mpfn.controller.converter.TablaMaestraConverter;
import pe.gob.mpfn.model.Diligencia;
import pe.gob.mpfn.model.Expediente;
import pe.gob.mpfn.model.Parte;
import pe.gob.mpfn.model.Personal;
import pe.gob.mpfn.model.Proteccion;
import pe.gob.mpfn.model.TablaMaestra;
import pe.gob.mpfn.service.TablaMaestraService;

@ManagedBean(name = "tablaMaestraBean")
@SessionScoped
@Configurable
@RooSerializable
@RooJsfManagedBean(entity = TablaMaestra.class, beanName = "tablaMaestraBean")
public class TablaMaestraBean implements Serializable  {

	private static final long serialVersionUID = 1L;

	@Autowired
    TablaMaestraService tablaMaestraService;

	private String name = "TablaMaestras";

	private TablaMaestra tablaMaestra;

	private List<TablaMaestra> allTablaMaestras;

	private boolean dataVisible = false;

	private List<String> columns;

	private HtmlPanelGrid createPanelGrid;

	private HtmlPanelGrid editPanelGrid;

	private HtmlPanelGrid viewPanelGrid;

	private boolean createDialogVisible = false;

	private List<Diligencia> selectedDiligencias;

	private List<Expediente> selectedExpedientes;

	private List<Expediente> selectedExpedientes1;

	private List<Expediente> selectedExpedientes2;

	private List<Parte> selectedPartes;

	private List<Parte> selectedPartes1;

	private List<Personal> selectedPersonals;

	private List<Proteccion> selectedProteccions;

	private List<Proteccion> selectedProteccions1;

	private List<Proteccion> selectedProteccions2;

	private List<TablaMaestra> selectedTablaMaestras;

	@PostConstruct
    public void init() {
        columns = new ArrayList<String>();
        columns.add("strDescripcion");
        columns.add("chrEstado");
    }

	public String getName() {
        return name;
    }

	public List<String> getColumns() {
        return columns;
    }

	public List<TablaMaestra> getAllTablaMaestras() {
        return allTablaMaestras;
    }

	public void setAllTablaMaestras(List<TablaMaestra> allTablaMaestras) {
        this.allTablaMaestras = allTablaMaestras;
    }

	public String findAllTablaMaestras() {
        allTablaMaestras = tablaMaestraService.findAllTablaMaestras();
        dataVisible = !allTablaMaestras.isEmpty();
        return null;
    }

	public boolean isDataVisible() {
        return dataVisible;
    }

	public void setDataVisible(boolean dataVisible) {
        this.dataVisible = dataVisible;
    }

	public HtmlPanelGrid getCreatePanelGrid() {
        if (createPanelGrid == null) {
            createPanelGrid = populateCreatePanel();
        }
        return createPanelGrid;
    }

	public void setCreatePanelGrid(HtmlPanelGrid createPanelGrid) {
        this.createPanelGrid = createPanelGrid;
    }

	public HtmlPanelGrid getEditPanelGrid() {
        if (editPanelGrid == null) {
            editPanelGrid = populateEditPanel();
        }
        return editPanelGrid;
    }

	public void setEditPanelGrid(HtmlPanelGrid editPanelGrid) {
        this.editPanelGrid = editPanelGrid;
    }

	public HtmlPanelGrid getViewPanelGrid() {
        if (viewPanelGrid == null) {
            viewPanelGrid = populateViewPanel();
        }
        return viewPanelGrid;
    }

	public void setViewPanelGrid(HtmlPanelGrid viewPanelGrid) {
        this.viewPanelGrid = viewPanelGrid;
    }

	public HtmlPanelGrid populateCreatePanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText diligenciasCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        diligenciasCreateOutput.setId("diligenciasCreateOutput");
        diligenciasCreateOutput.setValue("Diligencias:   ");
        htmlPanelGrid.getChildren().add(diligenciasCreateOutput);
        
        HtmlOutputText diligenciasCreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        diligenciasCreateInput.setId("diligenciasCreateInput");
        diligenciasCreateInput.setValue("This relationship is managed from the Diligencia side");
        htmlPanelGrid.getChildren().add(diligenciasCreateInput);
        
        Message diligenciasCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        diligenciasCreateInputMessage.setId("diligenciasCreateInputMessage");
        diligenciasCreateInputMessage.setFor("diligenciasCreateInput");
        diligenciasCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(diligenciasCreateInputMessage);
        
        HtmlOutputText expedientesCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientesCreateOutput.setId("expedientesCreateOutput");
        expedientesCreateOutput.setValue("Expedientes:   ");
        htmlPanelGrid.getChildren().add(expedientesCreateOutput);
        
        HtmlOutputText expedientesCreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientesCreateInput.setId("expedientesCreateInput");
        expedientesCreateInput.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientesCreateInput);
        
        Message expedientesCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        expedientesCreateInputMessage.setId("expedientesCreateInputMessage");
        expedientesCreateInputMessage.setFor("expedientesCreateInput");
        expedientesCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(expedientesCreateInputMessage);
        
        HtmlOutputText expedientes1CreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes1CreateOutput.setId("expedientes1CreateOutput");
        expedientes1CreateOutput.setValue("Expedientes1:   ");
        htmlPanelGrid.getChildren().add(expedientes1CreateOutput);
        
        HtmlOutputText expedientes1CreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes1CreateInput.setId("expedientes1CreateInput");
        expedientes1CreateInput.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientes1CreateInput);
        
        Message expedientes1CreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        expedientes1CreateInputMessage.setId("expedientes1CreateInputMessage");
        expedientes1CreateInputMessage.setFor("expedientes1CreateInput");
        expedientes1CreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(expedientes1CreateInputMessage);
        
        HtmlOutputText expedientes2CreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes2CreateOutput.setId("expedientes2CreateOutput");
        expedientes2CreateOutput.setValue("Expedientes2:   ");
        htmlPanelGrid.getChildren().add(expedientes2CreateOutput);
        
        HtmlOutputText expedientes2CreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes2CreateInput.setId("expedientes2CreateInput");
        expedientes2CreateInput.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientes2CreateInput);
        
        Message expedientes2CreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        expedientes2CreateInputMessage.setId("expedientes2CreateInputMessage");
        expedientes2CreateInputMessage.setFor("expedientes2CreateInput");
        expedientes2CreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(expedientes2CreateInputMessage);
        
        HtmlOutputText partesCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partesCreateOutput.setId("partesCreateOutput");
        partesCreateOutput.setValue("Partes:   ");
        htmlPanelGrid.getChildren().add(partesCreateOutput);
        
        HtmlOutputText partesCreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partesCreateInput.setId("partesCreateInput");
        partesCreateInput.setValue("This relationship is managed from the Parte side");
        htmlPanelGrid.getChildren().add(partesCreateInput);
        
        Message partesCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        partesCreateInputMessage.setId("partesCreateInputMessage");
        partesCreateInputMessage.setFor("partesCreateInput");
        partesCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(partesCreateInputMessage);
        
        HtmlOutputText partes1CreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partes1CreateOutput.setId("partes1CreateOutput");
        partes1CreateOutput.setValue("Partes1:   ");
        htmlPanelGrid.getChildren().add(partes1CreateOutput);
        
        HtmlOutputText partes1CreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partes1CreateInput.setId("partes1CreateInput");
        partes1CreateInput.setValue("This relationship is managed from the Parte side");
        htmlPanelGrid.getChildren().add(partes1CreateInput);
        
        Message partes1CreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        partes1CreateInputMessage.setId("partes1CreateInputMessage");
        partes1CreateInputMessage.setFor("partes1CreateInput");
        partes1CreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(partes1CreateInputMessage);
        
        HtmlOutputText personalsCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        personalsCreateOutput.setId("personalsCreateOutput");
        personalsCreateOutput.setValue("Personals:   ");
        htmlPanelGrid.getChildren().add(personalsCreateOutput);
        
        HtmlOutputText personalsCreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        personalsCreateInput.setId("personalsCreateInput");
        personalsCreateInput.setValue("This relationship is managed from the Personal side");
        htmlPanelGrid.getChildren().add(personalsCreateInput);
        
        Message personalsCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        personalsCreateInputMessage.setId("personalsCreateInputMessage");
        personalsCreateInputMessage.setFor("personalsCreateInput");
        personalsCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(personalsCreateInputMessage);
        
        HtmlOutputText proteccionsCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccionsCreateOutput.setId("proteccionsCreateOutput");
        proteccionsCreateOutput.setValue("Proteccions:   ");
        htmlPanelGrid.getChildren().add(proteccionsCreateOutput);
        
        HtmlOutputText proteccionsCreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccionsCreateInput.setId("proteccionsCreateInput");
        proteccionsCreateInput.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccionsCreateInput);
        
        Message proteccionsCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        proteccionsCreateInputMessage.setId("proteccionsCreateInputMessage");
        proteccionsCreateInputMessage.setFor("proteccionsCreateInput");
        proteccionsCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(proteccionsCreateInputMessage);
        
        HtmlOutputText proteccions1CreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions1CreateOutput.setId("proteccions1CreateOutput");
        proteccions1CreateOutput.setValue("Proteccions1:   ");
        htmlPanelGrid.getChildren().add(proteccions1CreateOutput);
        
        HtmlOutputText proteccions1CreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions1CreateInput.setId("proteccions1CreateInput");
        proteccions1CreateInput.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccions1CreateInput);
        
        Message proteccions1CreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        proteccions1CreateInputMessage.setId("proteccions1CreateInputMessage");
        proteccions1CreateInputMessage.setFor("proteccions1CreateInput");
        proteccions1CreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(proteccions1CreateInputMessage);
        
        HtmlOutputText proteccions2CreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions2CreateOutput.setId("proteccions2CreateOutput");
        proteccions2CreateOutput.setValue("Proteccions2:   ");
        htmlPanelGrid.getChildren().add(proteccions2CreateOutput);
        
        HtmlOutputText proteccions2CreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions2CreateInput.setId("proteccions2CreateInput");
        proteccions2CreateInput.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccions2CreateInput);
        
        Message proteccions2CreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        proteccions2CreateInputMessage.setId("proteccions2CreateInputMessage");
        proteccions2CreateInputMessage.setFor("proteccions2CreateInput");
        proteccions2CreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(proteccions2CreateInputMessage);
        
        HtmlOutputText tablaMaestrasCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestrasCreateOutput.setId("tablaMaestrasCreateOutput");
        tablaMaestrasCreateOutput.setValue("Tabla Maestras:   ");
        htmlPanelGrid.getChildren().add(tablaMaestrasCreateOutput);
        
        HtmlOutputText tablaMaestrasCreateInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestrasCreateInput.setId("tablaMaestrasCreateInput");
        tablaMaestrasCreateInput.setValue("This relationship is managed from the TablaMaestra side");
        htmlPanelGrid.getChildren().add(tablaMaestrasCreateInput);
        
        Message tablaMaestrasCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        tablaMaestrasCreateInputMessage.setId("tablaMaestrasCreateInputMessage");
        tablaMaestrasCreateInputMessage.setFor("tablaMaestrasCreateInput");
        tablaMaestrasCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(tablaMaestrasCreateInputMessage);
        
        HtmlOutputText tablaMaestraIntTablaIdCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestraIntTablaIdCreateOutput.setId("tablaMaestraIntTablaIdCreateOutput");
        tablaMaestraIntTablaIdCreateOutput.setValue("Tabla Maestra Int Tabla Id:   ");
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdCreateOutput);
        
        AutoComplete tablaMaestraIntTablaIdCreateInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        tablaMaestraIntTablaIdCreateInput.setId("tablaMaestraIntTablaIdCreateInput");
        tablaMaestraIntTablaIdCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.tablaMaestraIntTablaId}", TablaMaestra.class));
        tablaMaestraIntTablaIdCreateInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{tablaMaestraBean.completeTablaMaestraIntTablaId}", List.class, new Class[] { String.class }));
        tablaMaestraIntTablaIdCreateInput.setDropdown(true);
        tablaMaestraIntTablaIdCreateInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "tablaMaestraIntTablaId", String.class));
        tablaMaestraIntTablaIdCreateInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{tablaMaestraIntTablaId.strDescripcion} #{tablaMaestraIntTablaId.chrEstado}", String.class));
        tablaMaestraIntTablaIdCreateInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{tablaMaestraIntTablaId}", TablaMaestra.class));
        tablaMaestraIntTablaIdCreateInput.setConverter(new TablaMaestraConverter());
        tablaMaestraIntTablaIdCreateInput.setRequired(false);
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdCreateInput);
        
        Message tablaMaestraIntTablaIdCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        tablaMaestraIntTablaIdCreateInputMessage.setId("tablaMaestraIntTablaIdCreateInputMessage");
        tablaMaestraIntTablaIdCreateInputMessage.setFor("tablaMaestraIntTablaIdCreateInput");
        tablaMaestraIntTablaIdCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdCreateInputMessage);
        
        HtmlOutputText strDescripcionCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strDescripcionCreateOutput.setId("strDescripcionCreateOutput");
        strDescripcionCreateOutput.setValue("Str Descripcion: * ");
        htmlPanelGrid.getChildren().add(strDescripcionCreateOutput);
        
        InputTextarea strDescripcionCreateInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strDescripcionCreateInput.setId("strDescripcionCreateInput");
        strDescripcionCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.strDescripcion}", String.class));
        LengthValidator strDescripcionCreateInputValidator = new LengthValidator();
        strDescripcionCreateInputValidator.setMaximum(100);
        strDescripcionCreateInput.addValidator(strDescripcionCreateInputValidator);
        strDescripcionCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strDescripcionCreateInput);
        
        Message strDescripcionCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strDescripcionCreateInputMessage.setId("strDescripcionCreateInputMessage");
        strDescripcionCreateInputMessage.setFor("strDescripcionCreateInput");
        strDescripcionCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strDescripcionCreateInputMessage);
        
        HtmlOutputText chrEstadoCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoCreateOutput.setId("chrEstadoCreateOutput");
        chrEstadoCreateOutput.setValue("Chr Estado: * ");
        htmlPanelGrid.getChildren().add(chrEstadoCreateOutput);
        
        InputText chrEstadoCreateInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        chrEstadoCreateInput.setId("chrEstadoCreateInput");
        chrEstadoCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.chrEstado}", Character.class));
        chrEstadoCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(chrEstadoCreateInput);
        
        Message chrEstadoCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        chrEstadoCreateInputMessage.setId("chrEstadoCreateInputMessage");
        chrEstadoCreateInputMessage.setFor("chrEstadoCreateInput");
        chrEstadoCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(chrEstadoCreateInputMessage);
        
        return htmlPanelGrid;
    }

	public HtmlPanelGrid populateEditPanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText diligenciasEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        diligenciasEditOutput.setId("diligenciasEditOutput");
        diligenciasEditOutput.setValue("Diligencias:   ");
        htmlPanelGrid.getChildren().add(diligenciasEditOutput);
        
        HtmlOutputText diligenciasEditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        diligenciasEditInput.setId("diligenciasEditInput");
        diligenciasEditInput.setValue("This relationship is managed from the Diligencia side");
        htmlPanelGrid.getChildren().add(diligenciasEditInput);
        
        Message diligenciasEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        diligenciasEditInputMessage.setId("diligenciasEditInputMessage");
        diligenciasEditInputMessage.setFor("diligenciasEditInput");
        diligenciasEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(diligenciasEditInputMessage);
        
        HtmlOutputText expedientesEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientesEditOutput.setId("expedientesEditOutput");
        expedientesEditOutput.setValue("Expedientes:   ");
        htmlPanelGrid.getChildren().add(expedientesEditOutput);
        
        HtmlOutputText expedientesEditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientesEditInput.setId("expedientesEditInput");
        expedientesEditInput.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientesEditInput);
        
        Message expedientesEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        expedientesEditInputMessage.setId("expedientesEditInputMessage");
        expedientesEditInputMessage.setFor("expedientesEditInput");
        expedientesEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(expedientesEditInputMessage);
        
        HtmlOutputText expedientes1EditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes1EditOutput.setId("expedientes1EditOutput");
        expedientes1EditOutput.setValue("Expedientes1:   ");
        htmlPanelGrid.getChildren().add(expedientes1EditOutput);
        
        HtmlOutputText expedientes1EditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes1EditInput.setId("expedientes1EditInput");
        expedientes1EditInput.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientes1EditInput);
        
        Message expedientes1EditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        expedientes1EditInputMessage.setId("expedientes1EditInputMessage");
        expedientes1EditInputMessage.setFor("expedientes1EditInput");
        expedientes1EditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(expedientes1EditInputMessage);
        
        HtmlOutputText expedientes2EditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes2EditOutput.setId("expedientes2EditOutput");
        expedientes2EditOutput.setValue("Expedientes2:   ");
        htmlPanelGrid.getChildren().add(expedientes2EditOutput);
        
        HtmlOutputText expedientes2EditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes2EditInput.setId("expedientes2EditInput");
        expedientes2EditInput.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientes2EditInput);
        
        Message expedientes2EditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        expedientes2EditInputMessage.setId("expedientes2EditInputMessage");
        expedientes2EditInputMessage.setFor("expedientes2EditInput");
        expedientes2EditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(expedientes2EditInputMessage);
        
        HtmlOutputText partesEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partesEditOutput.setId("partesEditOutput");
        partesEditOutput.setValue("Partes:   ");
        htmlPanelGrid.getChildren().add(partesEditOutput);
        
        HtmlOutputText partesEditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partesEditInput.setId("partesEditInput");
        partesEditInput.setValue("This relationship is managed from the Parte side");
        htmlPanelGrid.getChildren().add(partesEditInput);
        
        Message partesEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        partesEditInputMessage.setId("partesEditInputMessage");
        partesEditInputMessage.setFor("partesEditInput");
        partesEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(partesEditInputMessage);
        
        HtmlOutputText partes1EditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partes1EditOutput.setId("partes1EditOutput");
        partes1EditOutput.setValue("Partes1:   ");
        htmlPanelGrid.getChildren().add(partes1EditOutput);
        
        HtmlOutputText partes1EditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partes1EditInput.setId("partes1EditInput");
        partes1EditInput.setValue("This relationship is managed from the Parte side");
        htmlPanelGrid.getChildren().add(partes1EditInput);
        
        Message partes1EditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        partes1EditInputMessage.setId("partes1EditInputMessage");
        partes1EditInputMessage.setFor("partes1EditInput");
        partes1EditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(partes1EditInputMessage);
        
        HtmlOutputText personalsEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        personalsEditOutput.setId("personalsEditOutput");
        personalsEditOutput.setValue("Personals:   ");
        htmlPanelGrid.getChildren().add(personalsEditOutput);
        
        HtmlOutputText personalsEditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        personalsEditInput.setId("personalsEditInput");
        personalsEditInput.setValue("This relationship is managed from the Personal side");
        htmlPanelGrid.getChildren().add(personalsEditInput);
        
        Message personalsEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        personalsEditInputMessage.setId("personalsEditInputMessage");
        personalsEditInputMessage.setFor("personalsEditInput");
        personalsEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(personalsEditInputMessage);
        
        HtmlOutputText proteccionsEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccionsEditOutput.setId("proteccionsEditOutput");
        proteccionsEditOutput.setValue("Proteccions:   ");
        htmlPanelGrid.getChildren().add(proteccionsEditOutput);
        
        HtmlOutputText proteccionsEditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccionsEditInput.setId("proteccionsEditInput");
        proteccionsEditInput.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccionsEditInput);
        
        Message proteccionsEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        proteccionsEditInputMessage.setId("proteccionsEditInputMessage");
        proteccionsEditInputMessage.setFor("proteccionsEditInput");
        proteccionsEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(proteccionsEditInputMessage);
        
        HtmlOutputText proteccions1EditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions1EditOutput.setId("proteccions1EditOutput");
        proteccions1EditOutput.setValue("Proteccions1:   ");
        htmlPanelGrid.getChildren().add(proteccions1EditOutput);
        
        HtmlOutputText proteccions1EditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions1EditInput.setId("proteccions1EditInput");
        proteccions1EditInput.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccions1EditInput);
        
        Message proteccions1EditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        proteccions1EditInputMessage.setId("proteccions1EditInputMessage");
        proteccions1EditInputMessage.setFor("proteccions1EditInput");
        proteccions1EditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(proteccions1EditInputMessage);
        
        HtmlOutputText proteccions2EditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions2EditOutput.setId("proteccions2EditOutput");
        proteccions2EditOutput.setValue("Proteccions2:   ");
        htmlPanelGrid.getChildren().add(proteccions2EditOutput);
        
        HtmlOutputText proteccions2EditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions2EditInput.setId("proteccions2EditInput");
        proteccions2EditInput.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccions2EditInput);
        
        Message proteccions2EditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        proteccions2EditInputMessage.setId("proteccions2EditInputMessage");
        proteccions2EditInputMessage.setFor("proteccions2EditInput");
        proteccions2EditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(proteccions2EditInputMessage);
        
        HtmlOutputText tablaMaestrasEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestrasEditOutput.setId("tablaMaestrasEditOutput");
        tablaMaestrasEditOutput.setValue("Tabla Maestras:   ");
        htmlPanelGrid.getChildren().add(tablaMaestrasEditOutput);
        
        HtmlOutputText tablaMaestrasEditInput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestrasEditInput.setId("tablaMaestrasEditInput");
        tablaMaestrasEditInput.setValue("This relationship is managed from the TablaMaestra side");
        htmlPanelGrid.getChildren().add(tablaMaestrasEditInput);
        
        Message tablaMaestrasEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        tablaMaestrasEditInputMessage.setId("tablaMaestrasEditInputMessage");
        tablaMaestrasEditInputMessage.setFor("tablaMaestrasEditInput");
        tablaMaestrasEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(tablaMaestrasEditInputMessage);
        
        HtmlOutputText tablaMaestraIntTablaIdEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestraIntTablaIdEditOutput.setId("tablaMaestraIntTablaIdEditOutput");
        tablaMaestraIntTablaIdEditOutput.setValue("Tabla Maestra Int Tabla Id:   ");
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdEditOutput);
        
        AutoComplete tablaMaestraIntTablaIdEditInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        tablaMaestraIntTablaIdEditInput.setId("tablaMaestraIntTablaIdEditInput");
        tablaMaestraIntTablaIdEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.tablaMaestraIntTablaId}", TablaMaestra.class));
        tablaMaestraIntTablaIdEditInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{tablaMaestraBean.completeTablaMaestraIntTablaId}", List.class, new Class[] { String.class }));
        tablaMaestraIntTablaIdEditInput.setDropdown(true);
        tablaMaestraIntTablaIdEditInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "tablaMaestraIntTablaId", String.class));
        tablaMaestraIntTablaIdEditInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{tablaMaestraIntTablaId.strDescripcion} #{tablaMaestraIntTablaId.chrEstado}", String.class));
        tablaMaestraIntTablaIdEditInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{tablaMaestraIntTablaId}", TablaMaestra.class));
        tablaMaestraIntTablaIdEditInput.setConverter(new TablaMaestraConverter());
        tablaMaestraIntTablaIdEditInput.setRequired(false);
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdEditInput);
        
        Message tablaMaestraIntTablaIdEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        tablaMaestraIntTablaIdEditInputMessage.setId("tablaMaestraIntTablaIdEditInputMessage");
        tablaMaestraIntTablaIdEditInputMessage.setFor("tablaMaestraIntTablaIdEditInput");
        tablaMaestraIntTablaIdEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdEditInputMessage);
        
        HtmlOutputText strDescripcionEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strDescripcionEditOutput.setId("strDescripcionEditOutput");
        strDescripcionEditOutput.setValue("Str Descripcion: * ");
        htmlPanelGrid.getChildren().add(strDescripcionEditOutput);
        
        InputTextarea strDescripcionEditInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strDescripcionEditInput.setId("strDescripcionEditInput");
        strDescripcionEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.strDescripcion}", String.class));
        LengthValidator strDescripcionEditInputValidator = new LengthValidator();
        strDescripcionEditInputValidator.setMaximum(100);
        strDescripcionEditInput.addValidator(strDescripcionEditInputValidator);
        strDescripcionEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strDescripcionEditInput);
        
        Message strDescripcionEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strDescripcionEditInputMessage.setId("strDescripcionEditInputMessage");
        strDescripcionEditInputMessage.setFor("strDescripcionEditInput");
        strDescripcionEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strDescripcionEditInputMessage);
        
        HtmlOutputText chrEstadoEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoEditOutput.setId("chrEstadoEditOutput");
        chrEstadoEditOutput.setValue("Chr Estado: * ");
        htmlPanelGrid.getChildren().add(chrEstadoEditOutput);
        
        InputText chrEstadoEditInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        chrEstadoEditInput.setId("chrEstadoEditInput");
        chrEstadoEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.chrEstado}", Character.class));
        chrEstadoEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(chrEstadoEditInput);
        
        Message chrEstadoEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        chrEstadoEditInputMessage.setId("chrEstadoEditInputMessage");
        chrEstadoEditInputMessage.setFor("chrEstadoEditInput");
        chrEstadoEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(chrEstadoEditInputMessage);
        
        return htmlPanelGrid;
    }

	public HtmlPanelGrid populateViewPanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText diligenciasLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        diligenciasLabel.setId("diligenciasLabel");
        diligenciasLabel.setValue("Diligencias:   ");
        htmlPanelGrid.getChildren().add(diligenciasLabel);
        
        HtmlOutputText diligenciasValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        diligenciasValue.setId("diligenciasValue");
        diligenciasValue.setValue("This relationship is managed from the Diligencia side");
        htmlPanelGrid.getChildren().add(diligenciasValue);
        
        HtmlOutputText expedientesLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientesLabel.setId("expedientesLabel");
        expedientesLabel.setValue("Expedientes:   ");
        htmlPanelGrid.getChildren().add(expedientesLabel);
        
        HtmlOutputText expedientesValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientesValue.setId("expedientesValue");
        expedientesValue.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientesValue);
        
        HtmlOutputText expedientes1Label = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes1Label.setId("expedientes1Label");
        expedientes1Label.setValue("Expedientes1:   ");
        htmlPanelGrid.getChildren().add(expedientes1Label);
        
        HtmlOutputText expedientes1Value = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes1Value.setId("expedientes1Value");
        expedientes1Value.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientes1Value);
        
        HtmlOutputText expedientes2Label = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes2Label.setId("expedientes2Label");
        expedientes2Label.setValue("Expedientes2:   ");
        htmlPanelGrid.getChildren().add(expedientes2Label);
        
        HtmlOutputText expedientes2Value = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        expedientes2Value.setId("expedientes2Value");
        expedientes2Value.setValue("This relationship is managed from the Expediente side");
        htmlPanelGrid.getChildren().add(expedientes2Value);
        
        HtmlOutputText partesLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partesLabel.setId("partesLabel");
        partesLabel.setValue("Partes:   ");
        htmlPanelGrid.getChildren().add(partesLabel);
        
        HtmlOutputText partesValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partesValue.setId("partesValue");
        partesValue.setValue("This relationship is managed from the Parte side");
        htmlPanelGrid.getChildren().add(partesValue);
        
        HtmlOutputText partes1Label = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partes1Label.setId("partes1Label");
        partes1Label.setValue("Partes1:   ");
        htmlPanelGrid.getChildren().add(partes1Label);
        
        HtmlOutputText partes1Value = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        partes1Value.setId("partes1Value");
        partes1Value.setValue("This relationship is managed from the Parte side");
        htmlPanelGrid.getChildren().add(partes1Value);
        
        HtmlOutputText personalsLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        personalsLabel.setId("personalsLabel");
        personalsLabel.setValue("Personals:   ");
        htmlPanelGrid.getChildren().add(personalsLabel);
        
        HtmlOutputText personalsValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        personalsValue.setId("personalsValue");
        personalsValue.setValue("This relationship is managed from the Personal side");
        htmlPanelGrid.getChildren().add(personalsValue);
        
        HtmlOutputText proteccionsLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccionsLabel.setId("proteccionsLabel");
        proteccionsLabel.setValue("Proteccions:   ");
        htmlPanelGrid.getChildren().add(proteccionsLabel);
        
        HtmlOutputText proteccionsValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccionsValue.setId("proteccionsValue");
        proteccionsValue.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccionsValue);
        
        HtmlOutputText proteccions1Label = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions1Label.setId("proteccions1Label");
        proteccions1Label.setValue("Proteccions1:   ");
        htmlPanelGrid.getChildren().add(proteccions1Label);
        
        HtmlOutputText proteccions1Value = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions1Value.setId("proteccions1Value");
        proteccions1Value.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccions1Value);
        
        HtmlOutputText proteccions2Label = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions2Label.setId("proteccions2Label");
        proteccions2Label.setValue("Proteccions2:   ");
        htmlPanelGrid.getChildren().add(proteccions2Label);
        
        HtmlOutputText proteccions2Value = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        proteccions2Value.setId("proteccions2Value");
        proteccions2Value.setValue("This relationship is managed from the Proteccion side");
        htmlPanelGrid.getChildren().add(proteccions2Value);
        
        HtmlOutputText tablaMaestrasLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestrasLabel.setId("tablaMaestrasLabel");
        tablaMaestrasLabel.setValue("Tabla Maestras:   ");
        htmlPanelGrid.getChildren().add(tablaMaestrasLabel);
        
        HtmlOutputText tablaMaestrasValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestrasValue.setId("tablaMaestrasValue");
        tablaMaestrasValue.setValue("This relationship is managed from the TablaMaestra side");
        htmlPanelGrid.getChildren().add(tablaMaestrasValue);
        
        HtmlOutputText tablaMaestraIntTablaIdLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestraIntTablaIdLabel.setId("tablaMaestraIntTablaIdLabel");
        tablaMaestraIntTablaIdLabel.setValue("Tabla Maestra Int Tabla Id:   ");
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdLabel);
        
        HtmlOutputText tablaMaestraIntTablaIdValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        tablaMaestraIntTablaIdValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.tablaMaestraIntTablaId}", TablaMaestra.class));
        tablaMaestraIntTablaIdValue.setConverter(new TablaMaestraConverter());
        htmlPanelGrid.getChildren().add(tablaMaestraIntTablaIdValue);
        
        HtmlOutputText strDescripcionLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strDescripcionLabel.setId("strDescripcionLabel");
        strDescripcionLabel.setValue("Str Descripcion:   ");
        htmlPanelGrid.getChildren().add(strDescripcionLabel);
        
        InputTextarea strDescripcionValue = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strDescripcionValue.setId("strDescripcionValue");
        strDescripcionValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.strDescripcion}", String.class));
        strDescripcionValue.setReadonly(true);
        strDescripcionValue.setDisabled(true);
        htmlPanelGrid.getChildren().add(strDescripcionValue);
        
        HtmlOutputText chrEstadoLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoLabel.setId("chrEstadoLabel");
        chrEstadoLabel.setValue("Chr Estado:   ");
        htmlPanelGrid.getChildren().add(chrEstadoLabel);
        
        HtmlOutputText chrEstadoValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{tablaMaestraBean.tablaMaestra.chrEstado}", String.class));
        htmlPanelGrid.getChildren().add(chrEstadoValue);
        
        return htmlPanelGrid;
    }

	public TablaMaestra getTablaMaestra() {
        if (tablaMaestra == null) {
            tablaMaestra = new TablaMaestra();
        }
        return tablaMaestra;
    }

	public void setTablaMaestra(TablaMaestra tablaMaestra) {
        this.tablaMaestra = tablaMaestra;
    }

	public List<Diligencia> getSelectedDiligencias() {
        return selectedDiligencias;
    }

	public void setSelectedDiligencias(List<Diligencia> selectedDiligencias) {
        if (selectedDiligencias != null) {
            tablaMaestra.setDiligencias(new HashSet<Diligencia>(selectedDiligencias));
        }
        this.selectedDiligencias = selectedDiligencias;
    }

	public List<Expediente> getSelectedExpedientes() {
        return selectedExpedientes;
    }

	public void setSelectedExpedientes(List<Expediente> selectedExpedientes) {
        if (selectedExpedientes != null) {
            tablaMaestra.setExpedientes(new HashSet<Expediente>(selectedExpedientes));
        }
        this.selectedExpedientes = selectedExpedientes;
    }

	public List<Expediente> getSelectedExpedientes1() {
        return selectedExpedientes1;
    }

	public void setSelectedExpedientes1(List<Expediente> selectedExpedientes1) {
        if (selectedExpedientes1 != null) {
            tablaMaestra.setExpedientes1(new HashSet<Expediente>(selectedExpedientes1));
        }
        this.selectedExpedientes1 = selectedExpedientes1;
    }

	public List<Expediente> getSelectedExpedientes2() {
        return selectedExpedientes2;
    }

	public void setSelectedExpedientes2(List<Expediente> selectedExpedientes2) {
        if (selectedExpedientes2 != null) {
            tablaMaestra.setExpedientes2(new HashSet<Expediente>(selectedExpedientes2));
        }
        this.selectedExpedientes2 = selectedExpedientes2;
    }

	public List<Parte> getSelectedPartes() {
        return selectedPartes;
    }

	public void setSelectedPartes(List<Parte> selectedPartes) {
        if (selectedPartes != null) {
            tablaMaestra.setPartes(new HashSet<Parte>(selectedPartes));
        }
        this.selectedPartes = selectedPartes;
    }

	public List<Parte> getSelectedPartes1() {
        return selectedPartes1;
    }

	public void setSelectedPartes1(List<Parte> selectedPartes1) {
        if (selectedPartes1 != null) {
            tablaMaestra.setPartes1(new HashSet<Parte>(selectedPartes1));
        }
        this.selectedPartes1 = selectedPartes1;
    }

	public List<Personal> getSelectedPersonals() {
        return selectedPersonals;
    }

	public void setSelectedPersonals(List<Personal> selectedPersonals) {
        if (selectedPersonals != null) {
            tablaMaestra.setPersonals(new HashSet<Personal>(selectedPersonals));
        }
        this.selectedPersonals = selectedPersonals;
    }

	public List<Proteccion> getSelectedProteccions() {
        return selectedProteccions;
    }

	public void setSelectedProteccions(List<Proteccion> selectedProteccions) {
        if (selectedProteccions != null) {
            tablaMaestra.setProteccions(new HashSet<Proteccion>(selectedProteccions));
        }
        this.selectedProteccions = selectedProteccions;
    }

	public List<Proteccion> getSelectedProteccions1() {
        return selectedProteccions1;
    }

	public void setSelectedProteccions1(List<Proteccion> selectedProteccions1) {
        if (selectedProteccions1 != null) {
            tablaMaestra.setProteccions1(new HashSet<Proteccion>(selectedProteccions1));
        }
        this.selectedProteccions1 = selectedProteccions1;
    }

	public List<Proteccion> getSelectedProteccions2() {
        return selectedProteccions2;
    }

	public void setSelectedProteccions2(List<Proteccion> selectedProteccions2) {
        if (selectedProteccions2 != null) {
            tablaMaestra.setProteccions2(new HashSet<Proteccion>(selectedProteccions2));
        }
        this.selectedProteccions2 = selectedProteccions2;
    }

	public List<TablaMaestra> getSelectedTablaMaestras() {
        return selectedTablaMaestras;
    }

	public void setSelectedTablaMaestras(List<TablaMaestra> selectedTablaMaestras) {
        if (selectedTablaMaestras != null) {
            tablaMaestra.setTablaMaestras(new HashSet<TablaMaestra>(selectedTablaMaestras));
        }
        this.selectedTablaMaestras = selectedTablaMaestras;
    }

	public List<TablaMaestra> completeTablaMaestraIntTablaId(String query) {
        List<TablaMaestra> suggestions = new ArrayList<TablaMaestra>();
        for (TablaMaestra tablaMaestra : tablaMaestraService.findAllTablaMaestras()) {
            String tablaMaestraStr = String.valueOf(tablaMaestra.getStrDescripcion() +  " "  + tablaMaestra.getChrEstado());
            if (tablaMaestraStr.toLowerCase().startsWith(query.toLowerCase())) {
                suggestions.add(tablaMaestra);
            }
        }
        return suggestions;
    }

	public String onEdit() {
        if (tablaMaestra != null && tablaMaestra.getDiligencias() != null) {
            selectedDiligencias = new ArrayList<Diligencia>(tablaMaestra.getDiligencias());
        }
        if (tablaMaestra != null && tablaMaestra.getExpedientes() != null) {
            selectedExpedientes = new ArrayList<Expediente>(tablaMaestra.getExpedientes());
        }
        if (tablaMaestra != null && tablaMaestra.getExpedientes1() != null) {
            selectedExpedientes1 = new ArrayList<Expediente>(tablaMaestra.getExpedientes1());
        }
        if (tablaMaestra != null && tablaMaestra.getExpedientes2() != null) {
            selectedExpedientes2 = new ArrayList<Expediente>(tablaMaestra.getExpedientes2());
        }
        if (tablaMaestra != null && tablaMaestra.getPartes() != null) {
            selectedPartes = new ArrayList<Parte>(tablaMaestra.getPartes());
        }
        if (tablaMaestra != null && tablaMaestra.getPartes1() != null) {
            selectedPartes1 = new ArrayList<Parte>(tablaMaestra.getPartes1());
        }
        if (tablaMaestra != null && tablaMaestra.getPersonals() != null) {
            selectedPersonals = new ArrayList<Personal>(tablaMaestra.getPersonals());
        }
        if (tablaMaestra != null && tablaMaestra.getProteccions() != null) {
            selectedProteccions = new ArrayList<Proteccion>(tablaMaestra.getProteccions());
        }
        if (tablaMaestra != null && tablaMaestra.getProteccions1() != null) {
            selectedProteccions1 = new ArrayList<Proteccion>(tablaMaestra.getProteccions1());
        }
        if (tablaMaestra != null && tablaMaestra.getProteccions2() != null) {
            selectedProteccions2 = new ArrayList<Proteccion>(tablaMaestra.getProteccions2());
        }
        if (tablaMaestra != null && tablaMaestra.getTablaMaestras() != null) {
            selectedTablaMaestras = new ArrayList<TablaMaestra>(tablaMaestra.getTablaMaestras());
        }
        return null;
    }

	public boolean isCreateDialogVisible() {
        return createDialogVisible;
    }

	public void setCreateDialogVisible(boolean createDialogVisible) {
        this.createDialogVisible = createDialogVisible;
    }

	public String displayList() {
        createDialogVisible = false;
        findAllTablaMaestras();
        return "tablaMaestra";
    }

	public String displayCreateDialog() {
        tablaMaestra = new TablaMaestra();
        createDialogVisible = true;
        return "tablaMaestra";
    }

	public String persist() {
        String message = "";
        if (tablaMaestra.getIntTablaId() != null) {
            tablaMaestraService.updateTablaMaestra(tablaMaestra);
            message = "Successfully updated";
        } else {
            tablaMaestraService.saveTablaMaestra(tablaMaestra);
            message = "Successfully created";
        }
        RequestContext context = RequestContext.getCurrentInstance();
        context.execute("createDialog.hide()");
        context.execute("editDialog.hide()");
        
        FacesMessage facesMessage = new FacesMessage(message);
        FacesContext.getCurrentInstance().addMessage(null, facesMessage);
        reset();
        return findAllTablaMaestras();
    }

	public String delete() {
        tablaMaestraService.deleteTablaMaestra(tablaMaestra);
        FacesMessage facesMessage = new FacesMessage("Successfully deleted");
        FacesContext.getCurrentInstance().addMessage(null, facesMessage);
        reset();
        return findAllTablaMaestras();
    }

	public void reset() {
        tablaMaestra = null;
        selectedDiligencias = null;
        selectedExpedientes = null;
        selectedExpedientes1 = null;
        selectedExpedientes2 = null;
        selectedPartes = null;
        selectedPartes1 = null;
        selectedPersonals = null;
        selectedProteccions = null;
        selectedProteccions1 = null;
        selectedProteccions2 = null;
        selectedTablaMaestras = null;
        createDialogVisible = false;
    }

	public void handleDialogClose(CloseEvent event) {
        reset();
    }
}
